import {$alert} from "@kordar/easyui";
import {tt} from "@kordar-lib/i18n";
import {resourceService} from "@kordar/easyui-tpl";

export function getBucket(id, success, error) {
    if (!id) {
        $alert.info(tt("warn", "Message", "Warning"), tt("invalid_dataset", "Message", "Invalid Dataset"))
        error && error()
        return
    }
    let fetch = async function () {
        let {code, message, data} = await resourceService.info("bucket", {conditions: [{key: 'id', value: id}]})
        let info = data.info
        if (code !== 200 || Object.keys(info).length === 0) {
            $alert.info(tt("warn", "Message", "Warning"), tt("invalid_dataset", "Message", "Invalid Dataset"))
            error && error()
        } else {
            success && success(info);
        }
    }
    fetch().then()
}

export function getParentDirectory(path) {
    let parts = path.split('/'); // 将路径拆分成数组
    parts.pop(); // 移除最后一个部分（当前目录）
    return parts.join('/'); // 重新拼接
}